<div class="row-fluid" style="margin-bottom: 10px;">
    <div class="span12">
        <div class="box">
            <div class="tab-header">
                <i class="icon-file" style="margin-left: 10px;"></i><?= lang('label_view') ?></div>

            <div class="padded" id="action_load_mudle">
                <!-- action contant  -->
                <h4><?= $result->name ?></h4>

                <?= timespan($result->create_date); ?>
                <br />
                <strong><?= lang('label_username') ?>: </strong><a href="<?= base_url(ADMIN_FOLDER . "/users/view/$result->user_id") ?>" target="_blank"><?= get_username_with_id($result->user_id) ?></a>
                <br />
                <strong><?= lang('label_store') ?>: </strong><a href="<?= base_url(ADMIN_FOLDER . "/stores/view/$result->store_id") ?>" target="_blank"><?= get_store_name_by_id($result->store_id) ?></a>

                <div style="border: #CDCDCD dashed 2px; padding: 15px;margin-bottom: 15px">
                    <?php echo $result->reson; ?>
                </div>
                <form class="form-horizontal private_message_form" action="<?= current_url() ?>" method="post" id="form-validate">
                    <div class="control-group">
                        <label class="control-label" for="private_message_reply"><?= lang('label_replay') ?>
                            <br /><br />
                            <button type="button" id="privaye_message_add_reply" class="btn btn-primary"><li class="icon-plus" style="margin-left: 5px"></li><?= lang('label_add') ?></button>
                        </label>
                        <div class="controls">
                            <textarea rows="4" style="width: 550px" name="comment" id="private_message_reply"></textarea>
                        </div>
                    </div>
                </form>

                <ul id="listview">
                    <li id="newreplaies"></li>
                    <form class="form-horizontal formeditreplaies" action="<?= current_url() ?>" method="post" id="form-validate" enctype="multipart/form-data">
                        <?php if ($reply) { ?>
                            <?php foreach ($reply as $val) { ?>
                                <li style="border: #CDCDCD dashed 2px; padding: 15px;margin-bottom: 15px">
                                    <strong><span><?= $val->username ?></span></strong> <span style="margin-right: 15px;display: inline-block;color: #B0B0B0;"><?= timespan($val->create_date) ?></span>
                                    <br />
                                    <textarea rows="4" style="width: 550px" name="editedcomment[<?= $val->id ?>]" ><?= $val->comment ?></textarea>
                                </li>
                            <?php } ?>
                        <?php } ?>
                    </form>
                </ul>

                <div class="tool">
                    <?php if ($result->close == 'NO') { ?>
                        <a class="btn btn-warning" href="<?= base_url(ADMIN_FOLDER . "/cases/close/$result->id"); ?>"><i class="icon-lock"></i>&nbsp;&nbsp;&nbsp;<?= lang('label_close') ?></a>
                    <?php } elseif (in_array($result->close, array('USER', 'ADMIN'))) { ?>
                        <a class="btn btn-inverse" href="<?= base_url(ADMIN_FOLDER . "/cases/open/$result->id"); ?>"><i class="icon-ban-circle"></i>&nbsp;&nbsp;&nbsp;<?= lang("label_closed_by_$result->close") . ' (' . lang('label_open') . ')' ?></a>
                        <?php
                    }
                    ?>
                    <a class="btn btn-primary editreplaies" href="javascript:void(0)"><i class="icon-edit" ></i>&nbsp;&nbsp;&nbsp;<?= lang('label_edit') ?></a>
                    <a class="delete_confirm btn btn-danger" href="<?= base_url() . ADMIN_FOLDER . '/' . get_segment(2) ?>/delete/<?= $result->id ?>"><i class="icon-trash"></i>&nbsp;&nbsp;&nbsp;<?= lang('label_delete') ?></a>
                </div>

            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function() {
        $('#privaye_message_add_reply').bind('click', function() {
            if ($('#private_message_reply').val() == '') {
                $('#private_message_reply').css({'border': 'red solid 1px'});
            } else {
                $.ajax({
                    url: '<?php echo base_url(ADMIN_FOLDER . "/cases/add_replay/$result->id") ?>',
                    type: 'POST',
                    data: $('.private_message_form').serialize(),
                    error: function() {
                        alert('<?= lang('message_save_error') ?>');
                    },
                    success: function(data) {
                        $('#newreplaies').append(data).fadeIn("slow");
                    }
                });
            }
            return false;
        });

        $('.editreplaies').bind('click', function() {
            $.ajax({
                url: '<?php echo base_url(ADMIN_FOLDER . "/cases/edit_replaies/$result->id") ?>',
                type: 'POST',
                data: $('.formeditreplaies').serialize(),
                error: function() {
                    alert('<?= lang('message_save_error') ?>');
                },
                success: function(data) {
                    location.href = '<?= current_url() ?>'
                }
            });
            return false;
        });
    });

</script>
